package nju.bean.meeting.UML;

import java.awt.Graphics;
import java.awt.Point;
/**
 * 所谓PlainArrow，就是这样的一个箭头: ⟶
 * @author gongshw
 */
@SuppressWarnings("serial")
public final class PlainArrow extends Arrow {
	private Point left=new Point();
	private Point right=new Point();
	
	@Override
	public void drawBy(Graphics g, Dot startDot, Dot endDot) {
        start = startDot.toPoint();
        end = endDot.toPoint();
        if(start.getX()<=end.getX()){
            left.setLocation(end.getX()-10*Math.cos(Math.PI/6+Math.atan((start.getY()-end.getY())/(end.getX()-start.getX()))), end.getY()+10*Math.sin(Math.PI/6+Math.atan((start.getY()-end.getY())/(end.getX()-start.getX()))));
            right.setLocation(end.getX()-10*Math.cos(Math.PI/6-Math.atan((start.getY()-end.getY())/(end.getX()-start.getX()))), end.getY()-10*Math.sin(Math.PI/6-Math.atan((start.getY()-end.getY())/(end.getX()-start.getX()))));
        }else{
            left.setLocation(end.getX()+10*Math.cos(Math.PI/6+Math.atan((start.getY()-end.getY())/(end.getX()-start.getX()))), end.getY()-10*Math.sin(Math.PI/6+Math.atan((start.getY()-end.getY())/(end.getX()-start.getX()))));
            right.setLocation(end.getX()+10*Math.cos(Math.PI/6-Math.atan((start.getY()-end.getY())/(end.getX()-start.getX()))), end.getY()+10*Math.sin(Math.PI/6-Math.atan((start.getY()-end.getY())/(end.getX()-start.getX()))));
        }
        g.drawLine((int)end.getX(), (int)end.getY(), (int)left.getX(), (int)left.getY());
        g.drawLine((int)end.getX(), (int)end.getY(), (int)right.getX(), (int)right.getY());
	}
	
	@Override
	public Point getBack(Dot start, Dot end) {
		// TODO Auto-generated method stub
		return end.toPoint();
	}
	
}
